Merge conflicts solutioned
[RRRRHHHH_Code] / ruralHouses client / src / gui / RequestNewHouseGUI.java
1 package gui;
2
3 import java.awt.Color;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.rmi.Naming;
7 import java.rmi.RemoteException;
8
9 import javax.swing.DefaultComboBoxModel;
10 import javax.swing.GroupLayout;
11 import javax.swing.GroupLayout.Alignment;
12 import javax.swing.JButton;
13 import javax.swing.JComboBox;
14 import javax.swing.JFrame;
15 import javax.swing.JLabel;
16 import javax.swing.JPanel;
17 import javax.swing.JTextField;
18 import javax.swing.LayoutStyle.ComponentPlacement;
19 import javax.swing.SwingConstants;
20 import javax.swing.border.EmptyBorder;
21
22 import common.AdminInterface;
23
24 import configuration.___IntNames;
25 import domain.Districs;
26 import domain.HouseFeatures;
27 import domain.Owner;
28 import domain.RuralHouse;
29
30 public class RequestNewHouseGUI extends JFrame {
31
32         /**
33          * 
34          */
35         private static final long serialVersionUID = 1L;
36         private JPanel contentPane;
37         private Owner owner;
38         private JLabel lblCode ;
39         private JLabel feedback = new JLabel("");
40         private JTextField Code_f;
41         private JLabel lblTown;
42         private JLabel lblDescription;
43         private JTextField description_f;
44         private JLabel lblKitchen;
45         private JTextField kitchens_f;
46         private JLabel lblRooms;
47         private JTextField rooms_f;
48         private JLabel lblLivings;
49         private JTextField lRooms_f;
50         private JLabel lblParkings;
51         private JTextField parkings_f;
52         private JLabel lblBaths;
53         private JTextField baths_f;
54         private JButton btnRegister;
55         private AdminInterface am = null;
56         private JComboBox<String> comboBox;
57
58
59         /**
60          * Create the frame.
61          */
62         public RequestNewHouseGUI(Owner o) {
63                 comboBox = new JComboBox<String>(new DefaultComboBoxModel<String>(
64                                 Districs.longNames()));
65                 try {
66                         am = (AdminInterface) Naming
67                                         .lookup(___IntNames.AdminManager);
68                 } catch (Exception e1) {
69                         System.out.println("Error accessing remote authentication: "
70                                         + e1.toString());
71                 }
72                 this.setTitle("New House");
73                 setBackground(Color.WHITE);
74                 this.getContentPane().setLayout(null);
75                 owner = o;
76                 setBounds(100, 100, 500, 583);
77                 contentPane = new JPanel();
78                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
79                 setContentPane(contentPane);
80                 
81                 lblCode = new JLabel("House Name:");
82                 lblCode.setHorizontalAlignment(SwingConstants.RIGHT);
83                 
84                 Code_f = new JTextField();
85                 Code_f.setColumns(10);
86                 
87                 lblTown = new JLabel("District:");
88                 lblTown.setHorizontalAlignment(SwingConstants.RIGHT);
89                 
90                 lblDescription = new JLabel("Description(optional):");
91                 lblDescription.setHorizontalAlignment(SwingConstants.RIGHT);
92                 
93                 description_f = new JTextField();
94                 description_f.setToolTipText("");
95                 description_f.setHorizontalAlignment(SwingConstants.LEFT);
96                 description_f.setColumns(10);
97                 
98                 lblKitchen = new JLabel("Kitchens:");
99                 lblKitchen.setHorizontalAlignment(SwingConstants.RIGHT);
100                 
101                 kitchens_f = new JTextField();
102                 kitchens_f.setColumns(10);
103                 
104                 lblRooms = new JLabel("Rooms:");
105                 lblRooms.setHorizontalAlignment(SwingConstants.RIGHT);
106                 
107                 rooms_f = new JTextField();
108                 rooms_f.setColumns(10);
109                 
110                 lblLivings = new JLabel("Living rooms:");
111                 lblLivings.setHorizontalAlignment(SwingConstants.RIGHT);
112                 
113                 lRooms_f = new JTextField();
114                 lRooms_f.setColumns(10);
115                 
116                 lblParkings = new JLabel("Parkings:");
117                 lblParkings.setHorizontalAlignment(SwingConstants.RIGHT);
118                 
119                 parkings_f = new JTextField();
120                 parkings_f.setColumns(10);
121                 
122                 lblBaths = new JLabel("Baths:");
123                 lblBaths.setHorizontalAlignment(SwingConstants.RIGHT);
124                 
125                 baths_f = new JTextField();
126                 baths_f.setColumns(10);
127                 
128                 btnRegister = new JButton("Request registration");
129                 btnRegister.addActionListener(new ActionListener() {
130                         public void actionPerformed(ActionEvent arg0) {
131                                 RuralHouse rh = null;
132                                 try {
133                                         //TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.
134                                         rh = new RuralHouse(Code_f.getText(),
135                                                                 owner, description_f.getText(),
136                                                                 (String) comboBox.getSelectedItem(), new HouseFeatures(Integer.parseInt(rooms_f.getText()),
137                                                                                 Integer.parseInt(kitchens_f.getText()),
138                                                                                 Integer.parseInt(baths_f.getText()),
139                                                                                 Integer.parseInt(lRooms_f.getText()),
140                                                                                 Integer.parseInt(parkings_f.getText())) );
141                                 
142                                 }
143                                 catch(NumberFormatException e){
144                                         e.printStackTrace();
145                                 }
146                                 
147                                 try {
148                                         if(am.addAdditionRequest(rh)){
149                                                 feedback.setText("Request sended");
150                                         }else{
151                                                 feedback.setText("Request cannot be sended(Already added)");
152                                         }
153                                 } catch (RemoteException e) {
154                                         // TODO Auto-generated catch block
155                                         e.printStackTrace();
156                                 }
157                         }
158                 });
159                 
160                 
161                 
162                 
163                 GroupLayout gl_contentPane = new GroupLayout(contentPane);
164                 gl_contentPane.setHorizontalGroup(
165                         gl_contentPane.createParallelGroup(Alignment.LEADING)
166                                 .addGroup(gl_contentPane.createSequentialGroup()
167                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
168                                                 .addGroup(gl_contentPane.createSequentialGroup()
169                                                         .addContainerGap()
170                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
171                                                                 .addGroup(gl_contentPane.createSequentialGroup()
172                                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
173                                                                                 .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
174                                                                                         .addGroup(gl_contentPane.createSequentialGroup()
175                                                                                                 .addComponent(lblTown, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
176                                                                                                 .addGap(18)
177                                                                                                 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE))
178                                                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
179                                                                                                 .addGroup(gl_contentPane.createSequentialGroup()
180                                                                                                         .addComponent(lblLivings)
181                                                                                                         .addGap(18)
182                                                                                                         .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
183                                                                                                 .addGroup(gl_contentPane.createSequentialGroup()
184                                                                                                         .addComponent(lblCode)
185                                                                                                         .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
186                                                                                                         .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
187                                                                                 .addGroup(gl_contentPane.createSequentialGroup()
188                                                                                         .addComponent(lblBaths, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
189                                                                                         .addGap(18)
190                                                                                         .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
191                                                                         .addGap(29)
192                                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
193                                                                                 .addComponent(lblDescription)
194                                                                                 .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 164, GroupLayout.PREFERRED_SIZE)))
195                                                                 .addGroup(gl_contentPane.createSequentialGroup()
196                                                                         .addComponent(lblKitchen, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
197                                                                         .addGap(18)
198                                                                         .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
199                                                                 .addGroup(gl_contentPane.createSequentialGroup()
200                                                                         .addComponent(lblRooms, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
201                                                                         .addGap(18)
202                                                                         .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
203                                                 .addGroup(gl_contentPane.createSequentialGroup()
204                                                         .addGap(18)
205                                                         .addComponent(lblParkings, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE)
206                                                         .addPreferredGap(ComponentPlacement.UNRELATED)
207                                                         .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
208                                                 .addGroup(gl_contentPane.createSequentialGroup()
209                                                         .addGap(140)
210                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
211                                                                 .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)
212                                                                 .addComponent(btnRegister))))
213                                         .addContainerGap(97, Short.MAX_VALUE))
214                 );
215                 gl_contentPane.setVerticalGroup(
216                         gl_contentPane.createParallelGroup(Alignment.LEADING)
217                                 .addGroup(gl_contentPane.createSequentialGroup()
218                                         .addGap(20)
219                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
220                                                 .addGroup(gl_contentPane.createSequentialGroup()
221                                                         .addGap(63)
222                                                         .addComponent(lblDescription)
223                                                         .addPreferredGap(ComponentPlacement.RELATED)
224                                                         .addComponent(description_f, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
225                                                 .addGroup(gl_contentPane.createSequentialGroup()
226                                                         .addGap(60)
227                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
228                                                                 .addComponent(lblCode)
229                                                                 .addComponent(Code_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
230                                                         .addPreferredGap(ComponentPlacement.UNRELATED)
231                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
232                                                                 .addComponent(lblTown)
233                                                                 .addComponent(comboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
234                                                         .addGap(18)
235                                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
236                                                                 .addComponent(lblLivings)
237                                                                 .addComponent(lRooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
238                                         .addGap(63)
239                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
240                                                 .addGroup(gl_contentPane.createSequentialGroup()
241                                                         .addGap(3)
242                                                         .addComponent(lblRooms))
243                                                 .addComponent(rooms_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
244                                         .addPreferredGap(ComponentPlacement.RELATED)
245                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
246                                                 .addComponent(kitchens_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
247                                                 .addGroup(gl_contentPane.createSequentialGroup()
248                                                         .addGap(3)
249                                                         .addComponent(lblKitchen)))
250                                         .addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
251                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
252                                                 .addGroup(gl_contentPane.createSequentialGroup()
253                                                         .addGap(3)
254                                                         .addComponent(lblBaths))
255                                                 .addComponent(baths_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
256                                         .addGap(45)
257                                         .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
258                                                 .addComponent(lblParkings)
259                                                 .addComponent(parkings_f, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
260                                         .addGap(41)
261                                         .addComponent(feedback, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
262                                         .addPreferredGap(ComponentPlacement.UNRELATED)
263                                         .addComponent(btnRegister)
264                                         .addGap(54))
265                 );
266                 contentPane.setLayout(gl_contentPane);
267         }
268 }